package com.ourteam.workspace.api;

import org.apache.commons.lang3.StringUtils;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.workspace.dao.IWorkspaceResourceDAO;
import com.ourteam.workspace.dao.WorkspaceResourceDAOQueryBean;
import com.ourteam.workspace.domain.WorkspaceResourceBean;


public class WorkspaceResourceSearchModel extends AbstractSearchModel<WorkspaceResourceDAOQueryBean> {

	private long workspaceId;
	
	private String name;
	
	public long getWorkspaceId() {
		return workspaceId;
	}

	public void setWorkspaceId(long workspaceId) {
		this.workspaceId = workspaceId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String getMappedDAOField(String aProperty) {
		return WorkspaceResourceBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(WorkspaceResourceDAOQueryBean queryBean) throws Exception {
		
		WorkspaceResourceDAOQueryBean.Criteria criteria = queryBean.createCriteria();
		
		if(this.workspaceId  != 0) {
			criteria.andWorkspaceIdEqualTo(workspaceId);
		}
		
		if(StringUtils.isNoneBlank(this.name)) {
			criteria.andNameLike(this.name);
		}
		
		queryBean.setSortProperty(IWorkspaceResourceDAO.OrderIndex);
		
	}

}
